﻿using System.Windows.Input;

namespace SimpleTool.Base
{
    class EasyCommand : ICommand
    {

        private readonly Action<object?> execute;

        private readonly Func<bool> canexecute;

        public EasyCommand(Action<object?> obj, Func<bool> flag)
        {
            execute = obj; canexecute = flag;
        }

        public bool CanExecute(object? func)
        {
            if (canexecute == null) return true;
            return canexecute();
        }

        public void Execute(object? obj)
        {
            execute(obj);
        }

        public event EventHandler? CanExecuteChanged
        {
            add
            {
                CommandManager.RequerySuggested += value;
            }
            remove
            {
                CommandManager.RequerySuggested -= value;
            }
        }
    }
}
